﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Modules.quest.Display.QuestManager.*;
    import flash.text.*;
    import Classes.inventory.*;
    import Modules.stats.experiments.*;
    import Display.hud.components.*;
    import Modules.quest.Display.*;
    import Modules.stats.types.*;

    public class HUD extends Sprite {

        protected static const TIMER_TICK:int = 50;
        protected static const COUNT_RATE:int = 30;
        public static const COMP_COINS:String = "coins";
        public static const COMP_CASH:String = "cash";
        public static const COMP_GOODS:String = "goods";
        public static const COMP_PREMIUM_GOODS:String = "premium_goods";
        public static const COMP_ENERGY:String = "energy";
        public static const COMP_XP:String = "xp";
        public static const COMP_QUESTS:String = "quest";
        public static const COMP_QUEST_MANAGER_ICON:String = "questManIcon";
        public static const COMP_MINI_QUEST:String = "miniQuest";
        public static const COMP_REPUTATION:String = "reputation";
        public static const COMP_VISITSTACK:String = "visitStack";
        public static const TOP_BORDER:uint = 10;
        public static const LEFT_BORDER:uint = 50;
        public static const HUD_COMPONENTS:Array = [HUDCoinsComponent, HUDCashComponent, HUDEnergyComponent, HUDGoodsComponent, HUDPremiumGoodsComponent, HUDXPComponent, HUDReputationComponent, HUDQuestBarComponent, HUDVisitingEnergyComponent, HUDVisitingHomepageComponent, HUDFranchiseRequestComponent, HUDGetCurrencyComponent, HUDQuestManagerComponent, HUDQuestManagerIconComponent, HUDDailyDripComponent, HUDXPromoComponent, HUDVday2011Component, HUDVerticalStackComponent, HUDMiniGameComponent, HUDZMCButton, HUDPeddlerComponent];

        private var m_townNameText:JLabel;
        private var m_debugText:TextField;
        private var m_dirty:Boolean = false;
        private var m_lockVisualEffects:Boolean = false;
        protected var m_visit:Boolean = false;
        private var m_sideBar:HUDQuestBarComponent;
        private var m_components:Dictionary;
        private var m_trainClickCallback:Function = null;
        protected var m_streakBonus:StreakBonus;
        protected var m_leftQuestLayer:Sprite;
        protected var m_rightQuestLayer:Sprite;

        public function HUD(_arg1:Sprite, _arg2:Sprite){
            this.m_leftQuestLayer = _arg1;
            this.m_rightQuestLayer = _arg2;
            Global.hud = this;
            if (Global.player == null){
                this.applyConfig("default");
            } else {
                this.gotoDefaultConfig();
            };
            var _local3:XML = Global.gameSettings.getXML().dooberStreak[0];
            this.m_streakBonus = new StreakBonus(_local3);
            this.m_streakBonus.mouseEnabled = false;
            this.addChild(this.m_streakBonus);
            var _local4:HUDComponent = this.getComponent(HUD.COMP_XP);
            this.m_streakBonus.x = (_local4.x + StreakBonus.STREAKBONUS_XOFFSET);
            this.m_streakBonus.y = (_local4.y + StreakBonus.STREAKBONUS_YOFFSET);
        }
        private function gotoDefaultConfig():void{
            if (Global.player.isPremiumGoodsActive){
                this.applyConfig("default_premiumgoods");
            } else {
                this.applyConfig("default");
            };
            this.updateCommodities();
        }
        public function set sideMask(_arg1:Number):void{
            this.m_sideBar.container.mask_height = _arg1;
        }
        private function gotoVisitConfig():void{
            if (Global.player.isPremiumGoodsActive){
                this.applyConfig("visiting_premiumgoods");
            } else {
                this.applyConfig("visiting");
            };
            this.updateCommodities();
        }
        public function applyConfig(_arg1:String):void{
            var _local3:HUDComponent;
            var _local4:Dictionary;
            var _local5:HUDComponent;
            var _local6:int;
            var _local7:XML;
            var _local8:int;
            var _local9:XML;
            var _local10:XML;
            var _local11:HUDComponent;
            var _local12:String;
            var _local13:Class;
            var _local14:String;
            var _local15:HUDComponentContainer;
            var _local2:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_VDAY_2011);
            for each (_local3 in this.m_components) {
                _local3.reset();
                if (_local3.parent){
                    _local3.parent.removeChild(_local3);
                };
            };
            _local4 = (this.m_components) ? this.m_components : new Dictionary();
            for each (_local5 in _local4) {
                _local5.cleanUp();
            };
            this.m_components = null;
            this.m_components = new Dictionary();
            _local6 = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
            _local7 = Global.gameSettings.getXML();
            _local8 = 0;
            for each (_local9 in _local7.hudConfig.config) {
                if (_local9.@name == _arg1){
                    for each (_local10 in _local9.component) {
                        if ((((_local10.@type == "vday2011")) && ((_local2 == 0)))){
                        } else {
                            if (_local10.@name == "HUDGetCurrencyComponent"){
                            } else {
                                _local12 = String(_local10.@type);
                                if (_local4[_local12] != null){
                                    _local11 = _local4[_local12];
                                } else {
                                    if ((((_local6 == ExperimentDefinitions.USE_QUEST_MANAGER)) && ((_local12 == "miniQuest")))){
                                        _local13 = (getDefinitionByName(("Display.hud.components." + _local10.@name)) as Class);
                                        _local11 = new _local13(10, 10, 0, 260, 1, 2, 80, 400);
                                    } else {
                                        if ((((((_local6 == ExperimentDefinitions.NO_QUEST_MANAGER)) && ((((((_local12 == "miniQuest")) || ((_local12 == "questManIcon")))) || ((_local10.@name == "HUDQuestManagerComponent")))))) || ((((_local6 == ExperimentDefinitions.USE_QUEST_MANAGER)) && ((((_local12 == "quest")) && ((_local10.@name == "HUDQuestBarComponent")))))))){
                                            continue;
                                        };
                                        _local11 = new ((getDefinitionByName(("Display.hud.components." + _local10.@name)) as Class))();
                                        _local11.initWithXML(_local10);
                                    };
                                };
                                if (_local10.@name == "HUDQuestBarComponent"){
                                    this.m_sideBar = (_local11 as HUDQuestBarComponent);
                                };
                                _local11.refresh(false);
                                _local11.x = ((_local10.@xPos)=="prev") ? _local8 : _local10.@xPos;
                                _local11.y = _local10.@yPos;
                                _local8 = (_local11.x + _local11.width);
                                this.m_components[_local12] = _local11;
                                if (_local11.isVisible()){
                                    if (_local10.hasOwnProperty("@parent")){
                                        _local14 = _local10.@parent;
                                        if ((((Global.getVisiting() == Player.FAKE_USER_ID_STRING)) && ((_local10.@name == "HUDPeddlerComponent")))){
                                        };
                                        _local15 = (this.m_components[_local14] as HUDComponentContainer);
                                        _local15.addComponent(_local11);
                                    } else {
                                        if ((((((((_local12 == "quest")) || ((_local12 == "miniQuest")))) || ((_local12 == "questManIcon")))) || ((_local10.@name == "HUDQuestManagerComponent")))){
                                            this.m_leftQuestLayer.addChild(_local11);
                                        } else {
                                            if (Number(_local10.@xPos) > 670){
                                                this.m_rightQuestLayer.addChild(_local11);
                                            } else {
                                                addChild(_local11);
                                            };
                                        };
                                    };
                                };
                                _local11 = null;
                            };
                        };
                    };
                    _local4 = null;
                };
            };
        }
        public function debugToggleDebugTextVisibility():void{
            this.m_debugText.visible = !(this.m_debugText.visible);
        }
        public function updateCommodities():void{
            if (Global.player.commodities != null){
                Global.hud.goodsCap = Global.player.commodities.getCapacity(Commodities.GOODS_COMMODITY);
                Global.hud.goods = Global.player.commodities.getCount(Commodities.GOODS_COMMODITY);
                Global.hud.premium_goodsCap = Global.player.commodities.getCapacity(Commodities.PREMIUM_GOODS_COMMODITY);
                Global.hud.premium_goods = Global.player.commodities.getCount(Commodities.PREMIUM_GOODS_COMMODITY);
            };
        }
        public function updateDebugText():void{
            if ((((this.m_debugText == null)) || (!(this.m_debugText.visible)))){
                return;
            };
            var _local1 = "";
            this.m_debugText.text = _local1;
        }
        private function onGetCoins(_arg1:MouseEvent):void{
            UI.displayPopup(new GetCoinsDialog(ZLoc.t("Dialogs", "ImpulseMarketCash"), "", GenericDialogView.TYPE_YESNO, null, true));
        }
        public function conditionallyRefreshHUD(_arg1:Boolean=false):void{
            var _local2:HUDComponent;
            if (((this.m_dirty) || (_arg1))){
                for each (_local2 in this.m_components) {
                    _local2.refresh(this.m_lockVisualEffects);
                };
                this.m_dirty = false;
                this.m_lockVisualEffects = false;
            };
        }
        public function lockVisualEffectsForNextUpdate():void{
            this.m_lockVisualEffects = true;
        }
        public function unlockVisualEffects():void{
            this.m_lockVisualEffects = false;
        }
        public function isVisualEffectsLocked():Boolean{
            return (this.m_lockVisualEffects);
        }
        public function markDirty():void{
            this.m_dirty = true;
        }
        public function get townName():String{
            return (this.m_townNameText.getText());
        }
        public function set townName(_arg1:String):void{
            if (this.m_townNameText != null){
                return (this.m_townNameText.setText(_arg1));
            };
        }
        public function set gold(_arg1:int):void{
            if (this.m_components["coins"]){
                this.m_components["coins"].updateCounter(_arg1);
            };
        }
        public function set cash(_arg1:int):void{
            if (this.m_components["cash"]){
                this.m_components["cash"].updateCounter(_arg1);
            };
        }
        public function set goods(_arg1:int):void{
            this.resetGoodsHUDIfRequired();
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                this.m_components[COMP_PREMIUM_GOODS].updateCounter1(_arg1);
            } else {
                if (this.m_components[COMP_GOODS]){
                    this.m_components[COMP_GOODS].updateCounter(_arg1);
                };
            };
        }
        public function set goodsCap(_arg1:int):void{
            this.resetGoodsHUDIfRequired();
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                this.m_components[COMP_PREMIUM_GOODS].updateCounterCapacity1(_arg1);
            } else {
                if (this.m_components[COMP_GOODS]){
                    this.m_components[COMP_GOODS].updateCounterCapacity(_arg1);
                };
            };
        }
        public function set energy(_arg1:int):void{
            if (this.m_components["energy"]){
                this.m_components["energy"].updateCounter(_arg1);
            };
        }
        public function set premium_goods(_arg1:int):void{
            this.resetGoodsHUDIfRequired();
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                this.m_components[COMP_PREMIUM_GOODS].updateCounter2(_arg1);
            };
        }
        public function set premium_goodsCap(_arg1:int):void{
            this.resetGoodsHUDIfRequired();
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                this.m_components[COMP_PREMIUM_GOODS].updateCounterCapacity2(_arg1);
            };
        }
        public function set reputation(_arg1:int):void{
            if (this.m_components["reputation"]){
                this.m_components["reputation"].updateCounter(_arg1);
            };
        }
        public function set xp(_arg1:int):void{
            if (this.m_components["xp"]){
                this.m_components["xp"].updateCounter(_arg1);
            };
        }
        public function updateVdayCount():void{
            if (this.m_components["vday2011"]){
                this.m_components["vday2011"].updateCounter(null);
            };
        }
        public function updateMiniGame(_arg1:int=-1):void{
            if (this.m_components["miniGame"]){
                this.m_components["miniGame"].updateCounter(_arg1);
            };
        }
        public function setTutorial(_arg1:Boolean):void{
            this.applyConfig((_arg1) ? "tutorial" : "default");
        }
        public function setVisiting(_arg1:Boolean):void{
            this.m_visit = _arg1;
            this.refreshGoodsHUD();
        }
        private function resetGoodsHUDIfRequired():void{
            if (((Global.player.isPremiumGoodsActive) && (!(this.m_components[COMP_PREMIUM_GOODS])))){
                this.refreshGoodsHUD();
            };
            if (((!(Global.player.isPremiumGoodsActive)) && (!(this.m_components[COMP_GOODS])))){
                this.refreshGoodsHUD();
            };
        }
        public function refreshGoodsHUD():void{
            if (this.m_visit == true){
                this.gotoVisitConfig();
            } else {
                this.gotoDefaultConfig();
            };
        }
        public function getComponent(_arg1:String):HUDComponent{
            return (this.m_components[_arg1]);
        }
        public function showGoalsProgressOverlayOnQuestIcon(_arg1:String, _arg2:String, _arg3:Boolean=false):void{
            if (this.m_components["quest"]){
                this.m_components["quest"].showBanner(_arg1, _arg2, _arg3);
            };
        }
        public function addQuestSprite(_arg1:String, _arg2:DisplayObject, _arg3:String):void{
            if (this.m_components["quest"]){
                this.m_components["quest"].addIcon(_arg1, _arg3, _arg2, this.clickQuestIcon);
            };
        }
        public function removeQuestSprite(_arg1:String, _arg2:Boolean=true):void{
            var _local3:int;
            var _local4:QuestManagerSprite;
            if (this.m_components["quest"]){
                this.m_components["quest"].removeIcon(_arg1, this.clickQuestIcon, _arg2);
            } else {
                _local3 = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
                if (_local3 == ExperimentDefinitions.USE_QUEST_MANAGER){
                    _local4 = UI.questManagerView.content.removeIconByName(_arg1);
                    if (!_local4){
                        UI.questManagerView.content.popFirstQuestIcon();
                    };
                };
            };
        }
        public function showTrainQuestSprite(_arg1:DisplayObject, _arg2:Function):void{
            this.m_trainClickCallback = _arg2;
            var _local3:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
            if (_local3 == ExperimentDefinitions.USE_QUEST_MANAGER){
                if (this.m_components["miniQuest"]){
                    this.m_components["miniQuest"].addIcon("trainAtStation", ZLoc.t("Dialogs", "TrainUI_QuestHudTooltip"), _arg1, this.clickTrainIcon);
                };
            } else {
                if (this.m_components["quest"]){
                    this.m_components["quest"].addIcon("trainAtStation", ZLoc.t("Dialogs", "TrainUI_QuestHudTooltip"), _arg1, this.clickTrainIcon);
                };
            };
        }
        public function hideTrainQuestSprite():void{
            var _local1:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
            if (_local1 == ExperimentDefinitions.USE_QUEST_MANAGER){
                if (this.m_components["miniQuest"]){
                    this.m_components["miniQuest"].removeIcon("trainAtStation", this.clickTrainIcon);
                };
            } else {
                if (this.m_components["quest"]){
                    this.m_components["quest"].removeIcon("trainAtStation", this.clickTrainIcon);
                };
            };
        }
        public function showMiniQuestSprite(_arg1:String, _arg2:String, _arg3:DisplayObject, _arg4:Function, _arg5:int=0):Boolean{
            var _local6:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
            var _local7:Boolean;
            if (_local6 == ExperimentDefinitions.USE_QUEST_MANAGER){
                if (this.m_components["miniQuest"]){
                    this.m_components["miniQuest"].addIcon(_arg1, _arg2, _arg3, _arg4, _arg5);
                    _local7 = true;
                };
            } else {
                if (this.m_components["quest"]){
                    this.m_components["quest"].addIcon(_arg1, _arg2, _arg3, _arg4, _arg5);
                    _local7 = true;
                };
            };
            return (_local7);
        }
        public function hideMiniQuestSprite(_arg1:String, _arg2:Function):void{
            var _local3:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_QUEST_MANAGER);
            if (_local3 == ExperimentDefinitions.USE_QUEST_MANAGER){
                if (this.m_components["miniQuest"]){
                    this.m_components["miniQuest"].removeIcon(_arg1, _arg2);
                };
            } else {
                if (this.m_components["quest"]){
                    this.m_components["quest"].removeIcon(_arg1, _arg2);
                };
            };
        }
        public function set visitEnergy(_arg1:uint):void{
            if (this.m_components["visitStack"]){
                this.m_components["visitStack"].refresh(false);
            };
            if (this.m_components["visitEnergy"]){
                this.m_components["visitEnergy"].updateCounter(_arg1);
            };
        }
        protected function clickTrainIcon(_arg1:MouseEvent):void{
            this.m_trainClickCallback();
        }
        protected function clickQuestIcon(_arg1:MouseEvent):void{
            var _local2:String;
            if (this.m_components["quest"]){
                _local2 = _arg1.target.name;
                Sounds.play("click1");
                _arg1.stopPropagation();
                Global.questManager.pumpActivePopup(_local2);
                this.removeBanner(_local2);
                Global.ui.resetActionMenu();
                StatsManager.sample(100, StatsCounterType.HUD_COUNTER, StatsKingdomType.QUEST_ICONS, _local2);
            };
        }
        public function removeBanner(_arg1:String):void{
            if (this.m_components["quest"]){
                this.m_components["quest"].removeBanner(_arg1);
            };
        }
        public function cleanUpBanner(_arg1:QuestOverlaySprite):void{
            if (this.m_components["quest"]){
                this.m_components["quest"].cleanUpBanner(_arg1);
            };
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
            if (!Global.ui.turnOffHighlightedObject()){
                if (UI.hasCursor(Global.ui.getCursorId()) == false){
                    Global.ui.setCursorId(UI.setCursor(null));
                };
            };
            UI.pushBlankCursor();
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
            UI.popBlankCursor();
        }
        public function get streakBonus():StreakBonus{
            return (this.m_streakBonus);
        }
        public function addComponent(_arg1:String, _arg2:HUDComponent):void{
            this.m_components[_arg1] = _arg2;
        }
        public function setHUDComponentVisible(_arg1:String, _arg2:Boolean):void{
            if (this.m_components[_arg1]){
                (this.m_components[_arg1] as HUDComponent).visible = _arg2;
            };
        }
        public function attachComponentToUI(_arg1:String):void{
            var _local2:HUDComponent;
            if (((this.m_components[_arg1]) && ((this.m_components[_arg1].parent == this)))){
                _local2 = this.m_components[_arg1];
                this.removeChild(_local2);
                Global.ui.addChild(_local2);
            };
        }
        public function attachComponentBackToHUD(_arg1:String):void{
            var _local2:HUDComponent;
            if (((this.m_components[_arg1]) && ((this.m_components[_arg1].parent == Global.ui)))){
                _local2 = this.m_components[_arg1];
                Global.ui.removeChild(_local2);
                this.addChild(_local2);
            };
        }
        public function get hudGoodsPosition():Point{
            var _local1:Point = new Point(0, 0);
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                _local1.x = this.m_components[COMP_PREMIUM_GOODS].x;
                _local1.y = this.m_components[COMP_PREMIUM_GOODS].y;
            } else {
                if (this.m_components[COMP_GOODS]){
                    _local1.x = this.m_components[COMP_GOODS].x;
                    _local1.y = this.m_components[COMP_GOODS].y;
                };
            };
            return (_local1);
        }
        public function get hudGoodsHeight():Number{
            var _local1:Number = 0;
            if (((Global.player.isPremiumGoodsActive) && (this.m_components[COMP_PREMIUM_GOODS]))){
                _local1 = this.m_components[COMP_PREMIUM_GOODS].height;
            } else {
                if (this.m_components[COMP_GOODS]){
                    _local1 = this.m_components[COMP_GOODS].height;
                };
            };
            return (_local1);
        }

    }
}//package Display.hud 
